package com.wp.dao;

public class TestPaper implements Paper {

    private int charPerLine = 16;     // 每行字符数
    private int linePerPage = 5;      // 每页数量
    private String content = "";     // 纸张中类容
    private int posX = 0;             // 当前横向位置，从0到 charPerLine-1
    private int posY = 0;             // 当前行数，从0到 linePerPage-1
    private int posP = 1;             // 当前页数

    public String getContent(){
        String ret = this.content;

        if (!(posX == 0 && posY == 0)){
            int count = linePerPage - posY;
            for (int i =0; i< count; ++i){
                ret += Paper.newline;
            }
            ret += "==第" + posP + "页==";
        }
        return ret;
    }
    public void putInChar(char c){
        content += c;
        ++posX;
        if (posX == charPerLine){
            content += Paper.newline;
            posX = 0;
            ++posY;
        }

        // 判断是否翻页
        if (posY == linePerPage){
            content += "==第" + posP +"页==";
            content += Paper.newline + Paper.newline;
            posX = 0;
            ++posP;
        }
    }
    // 使用set方法注入每行字符数
    public void setCharPerLine(int charPerLine) {
        this.charPerLine = charPerLine;
    }
    // 使用set方法注入每页行数
    public void setLinePerPage(int linePerPage) {
        this.linePerPage = linePerPage;
    }
}
